package com.kingdee.eas.fm.fs.client;



import java.awt.event.ActionEvent;
import java.text.MessageFormat;
import java.util.Set;

import com.kingdee.bos.ctrl.kdf.table.IBlock;
import com.kingdee.bos.ctrl.kdf.table.ICell;
import com.kingdee.bos.ctrl.kdf.table.IRow;
import com.kingdee.bos.ctrl.kdf.table.KDTSelectBlock;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.base.netctrl.IMutexServiceControl;
import com.kingdee.eas.base.netctrl.MutexServiceControlFactory;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.fi.gl.GlUtils;
import com.kingdee.eas.fm.common.ContextHelperFactory;
import com.kingdee.eas.fm.common.FMHelper;
import com.kingdee.eas.fm.common.client.FMClientHelper;
import com.kingdee.eas.fm.common.client.MutexUtils;
import com.kingdee.eas.fm.fs.SettlementBillFactory;
import com.kingdee.eas.fm.fs.SettlementBillInfo;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.EASResource;
import com.kingdee.eas.util.client.MsgBox;

public class SettlementBillListUIPIEx extends SettlementBillListUI {

	public SettlementBillListUIPIEx() throws Exception {
		super();
	}
    private void showWarning(String resName)
    {
        MsgBox.showWarning(this, EASResource.getString("com.kingdee.eas.fm.fs.SettlementBillUI", resName));
        SysUtil.abort();
    }
    private void verifyCanEditOrRemove(IRow row)
    {
        if(row.getCell("auditor").getValue() != null)
            showWarning("ApprovedNotDeleteOrEdit");
        if(row.getCell("acceptor").getValue() != null)
            showWarning("AcceptedNotDeleteOrEdit");
        if(row.getCell("acceptDate").getValue() != null)
            showWarning("AcceptedNotDeleteOrEdit");
    }
	    public void actionRemove_actionPerformed(ActionEvent e)
	    throws Exception
	{
	    checkSelected();
	    String id =getSelectedKeyValue();
	    CompanyOrgUnitInfo company = ContextHelperFactory.getRemoteInstance().getCurrentCompany();
	    if(GlUtils.isCompanyUnion(company))
	        showWarning("CanNotDelByOnlyUnion");
	    if(MsgBox.isCancel(MsgBox.showConfirm2(this, EASResource.getString("com.kingdee.eas.framework.FrameWorkResource.Confirm_Delete"))))
	        return;
	    IBlock selectBlock;
	    int i;
	    selectBlock = null;
	    ICell cell = null;
	    i = 0;
	    int j;
	    if(i >= tblMain.getSelectManager().size())
	    selectBlock = KDTSelectBlock.change(tblMain, tblMain.getSelectManager().get(i));
	    SettlementBillInfo settlementBillInfo;
	    IMutexServiceControl iMutex;
	    settlementBillInfo = SettlementBillFactory.getRemoteInstance().getSettlementBillInfo(new ObjectUuidPK(id));
//	    Set src = FMHelper.getSrcBillIdSet(null, id.toString());
//	    if(src != null && src.size() > 0)
//	    {
//	        MsgBox.showError(EASResource.getString("com.kingdee.eas.fm.fs.FSAutoGenerateResource", "137_SettlementBillListUI"));
//	        SysUtil.abort();
//	    }
	    iMutex = MutexServiceControlFactory.getRemoteInstance();
	    boolean result = iMutex.requestObjIDForUpdate(id.toString());
	    if(!result)
	    {
	        String msg1 = MessageFormat.format(EASResource.getString("com.kingdee.eas.fm.fs.SettlementBillUI", "billLock"), new String[] {
	            settlementBillInfo.getNumber().toString()
	        });
	        MsgBox.showConfirm2(this, msg1);
	        SysUtil.abort();
	    }
	    getBizInterface().delete(new ObjectUuidPK(id));
	    Exception exception;
	    MutexUtils.releaseMutex(id.toString());
	    MutexUtils.releaseMutex(id.toString());
	    refreshList();
	    refresh(e);
	}
}
